package com.web.music.model;

//import java.util.ArrayList;
//import java.util.List;

import javax.persistence.*;


@NamedQueries({
	@NamedQuery(name="Track.findAllTracksByString",
		    query="SELECT e FROM Track e where e.title like :p_title"),
		    
	@NamedQuery(name = "Track.findAllTracksByArtistId", 
		    query = "select a from Track a, Album b, Artist c where a.album = b.id and b.artist = c.id and c.id=:p_artist_id"),

	/*select distinct a.* from Track a, Album b, Artist c1, Person d
    		where a.album_ALBUM_ID = b.ALBUM_ID and 
    		c1.artist_id = b.artist_ARTIST_ID and c1.person_id =d.person_id and d.person_id = :2
    	union
	 select distinct a.* from Track a, Album b, Band_Persons c1, Person d
    		where a.album_ALBUM_ID = b.ALBUM_ID and 
    		c1.artist_id = b.artist_ARTIST_ID and c1.person_id =d.person_id and d.person_id = :2;*/	
	@NamedQuery(name = "Track.findAllTracksByPersonId", 
		    query = "select distinct a from Track a, Album b, Singer c1, Person d "+
		    		"where a.album = b.id and " +
		    		"b.artist = c1.id and c1.person = d.id and d.id =:p_person_id " +
		    		"union " +
		    		"select distinct a from Track a, Album b, MusicBand c1, Person d "+
		    		"where a.album = b.id and " +
		    		"b.artist = c1.id and c1.members = d.id and d.id = :p_person_id ")		    
} )
@Entity
public class Track implements PersistentEntity {
	
	@Id
	@Column(name = "TRACK_ID", nullable = false)
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;

	@ManyToOne
	//@JoinColumn(name="ALBUM_ID", nullable = false)
	private Album album;
	
	private int num;
	private String title;
	private String mp3;	

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}
	
	public Album getAlbum(){
		return album;
	}
	public void setAlbum(Album album){
		this.album = album;
	}
	public int getNum(){
		return num;
	}
	public void setNum(int num){
		this.num = num;
	}
	public String getTitle(){
		return this.title;
	}
	public void setTitle(String title){
		this.title = title;
	}
	public String getMP3(){
		return this.mp3;
	}
	public void setMP3(String mp3){
		this.mp3 = mp3;
	}
}
